// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PUR_ARV_ITEM
// * CreateDate    : 2014-02-18 18:04:10
// * Creater       : CodeSmith
// * LastChangeDate: 2014-02-18 18:04:10
// * LastChanger   : 2014-02-18 18:04:10
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Pur
{
/// <summary>
    /// PurArvItem
    /// </summary>
    public partial class PurArvItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objPurArvItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static PurArvItemEntity GetPurArvItem(PurArvItemEntity objPurArvItemEntity)
        {
            return DataAccess.SelectSingle<PurArvItemEntity>(objPurArvItemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objPurArvItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertPurArvItem(PurArvItemEntity objPurArvItemEntity)
        {
            return DataAccess.Insert(objPurArvItemEntity);
        }

        public static bool InsertPurArvItem(List<PurArvItemEntity> objPurArvItemEntityList)
        {
            return DataAccess.Insert(objPurArvItemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objPurArvItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdatePurArvItem(PurArvItemEntity objPurArvItemEntity)
        {
            return DataAccess.Update(objPurArvItemEntity);
        }

        public static bool UpdatePurArvItem(List<PurArvItemEntity> objPurArvItemEntityList)
        {
            return DataAccess.Update<PurArvItemEntity>(objPurArvItemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objPurArvItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeletePurArvItem(PurArvItemEntity objPurArvItemEntity)
        {
            return DataAccess.Delete(objPurArvItemEntity);
        }

        public static bool DeletePurArvItem(List<PurArvItemEntity> objPurArvItemEntityList)
        {
            return DataAccess.Delete<PurArvItemEntity>(objPurArvItemEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetPurArvItemAll()
        {
            return DataAccess.SelectAllDataSet<PurArvItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<PurArvItemEntity> GetPurArvItemAllList()
        {
            return DataAccess.SelectAll<PurArvItemEntity>();
        }
        #endregion

        #region Functions
        public static DataSet GetArvItemQty(string poNo, string materialId)
        {
            string sql = @"select SUM(item.ACTURAL_ARV_QTY) as ARV_TOTAL_QTY,SUM(item.ACP_QTY) as ARV_ACP_QTY 
from PUR_ARV arv
left join PUR_ARV_ITEM item on arv.ARV_NO=item.ARV_NO
where arv.IS_ACTIVE=1 and arv.PO_NO='{0}' and item.MATERIAL_ID='{1}'";
            sql = string.Format(sql, poNo, materialId);
            return DataAccess.SelectDataSet(sql);
        }

        public static PurArvItemEntity GetArvItemForInvIoi(string arvId, string materialId)
        {
            string sql = @"select item.* from PUR_ARV arv
left join PUR_ARV_ITEM item on arv.ARV_NO=item.ARV_NO
where arv.ID='{0}' and item.MATERIAL_ID='{1}' and arv.IS_ACTIVE=1";
            sql = string.Format(sql, arvId, materialId);
            var items = DataAccess.Select<PurArvItemEntity>(sql);
            if (items == null || items.Count == 0)
                return null;
            else return items[0];
        }
        #endregion

	}
	
	
}	

